﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LibYanu.Web.Provider;
using LibYanu.Security.DTO;
using System.IO;
using Newtonsoft.Json;
namespace MvcTest.Controllers
{
    public class RolewController : Controller
    {

        public ActionResult RolePage()
        {
            ViewBag.Message = "yanuar";
            return View();
        }

        public ActionResult Welcome(string name)
        {

            ViewBag.Name = name;
            return View();
        }

        public ActionResult ListRole()
        {
            var p = new YanuRoleProvider();
            var m = p.GetAllModelRole();
            return View(m);
        }



        [HttpPost]
        public JsonResult getstring(string s)
        {
            var str=Request.InputStream;
            Request.InputStream.Position=0;
            var tojson=new StreamReader(str).ReadToEnd();
            AspnetRoleDto k = JsonConvert.DeserializeObject<AspnetRoleDto>(tojson);
            
            var m = new AspnetRoleDto() { LoweredRoleName = "office boy", RoleName = "Office Boy" };
            var st = Json(m);
            //return Json(s + DateTime.Now.ToString("HHmmss"));
            return Json(m);
        }
        //
        // GET: /Role/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Role/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Role/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Role/Create

        [HttpPost]
        public ActionResult Create(AspnetRoleDto collection)        
        {
            try
            {
                // TODO: Add insert logic here
                //collection
                var m = ModelState;
                
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Role/Edit/5

        public ActionResult Edit(int id)
        {
            var p = new YanuRoleProvider();
            var m = p.GetAllModelRole();
            return View("ListRole",m);
        }

        //
        // POST: /Role/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Role/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Role/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
